{extend name="public:member" /}
{block name="head_css"}
<link rel="stylesheet" href="__RES__/member/css/aftersales.css" />
{/block}
{block name="content"}
<div id="location">
	<div class="allWrap">
		<a href="{$Request.root.true}">首页</a><span>></span><a href="{:url('Aftersales/choice',array('id'=>input('param.id')))}">售后服务</a><span>></span><a>{$title}</a>
	</div>
</div>
<div id="refund" class="allWrap">
	
	<div id="step">		
		{if condition="1 eq $type"}		
			<ul class="three">
				<li class="on">1.买家申请{$title}</li>
				<li>2.商家处理{$title}申请</li>
				<li>3.商家处理完成</li>
			</ul>
		{else/}		
			<ul class="four">
				<li class="on">1.买家申请{$title}</li>
				<li>2.商家处理{$title}申请</li>
				<li>3.买家退货给商家</li>
				<li>4.商家处理完成</li>
			</ul>
		{/if}
	</div>
	
	<div class="order_pro"></div>	
	
	<div id="refund_form">
		<input type="hidden" name="order_id" value="{:input('id')}" />
		<input type="hidden" name="refund_type" value="{:input('type')}" />
		<h2>售后申请</h2>
		<ul>
			<li>
				<span><i>*</i>{$title}原因：</span>
				<select name="reason_id">  
					<option>--请选择{$title}原因--</option>					
					{volist name="reason" id="r"}
						<option value="{$r.reason_id}">{$r.title}</option>	
					{/volist}			       
         		</select>
			</li>
			<li>
				<span><i>*</i>退款金额：</span>
				<input name="refund_amount" class="text" type="text" />
			</li>
			<li>
				<span><i>*</i>{$title}说明：</span>
				<textarea name="buyer_message"></textarea>
			</li>
			<li id="upload_img">
				<span>上传凭证：</span>
				<div id="upload_box">					
					<div id="img_box">
						
					</div>
					<a id="upload">上传图片</a>
					<p>每张图片大小不超过5M，最多3张。</p>
                </div>
			</li>
			<li>				
				<button id="apply" class="button">提交申请</button>				
			</li>
		</ul>
	</div>

	
</div>

{/block}
{block name="javascript"}
<script src="__PUBLIC__/fileupload/jquery.ui.widget.js"></script>
<script src="__PUBLIC__/fileupload/jquery.fileupload.js"></script>
<script>
$('.order_pro').load('<?php echo url("Aftersales/goods_list",array("id"=>input("param.id"))); ?>');

var count=0;

$('#upload').click(function(){
	
	if(count>2){
		art.dialog({content:'每张图片大小不超过5M，最多3张图片', lock: true});
		return;
	}
	
	$('#form-upload').remove();
	
	$('body').prepend('<form enctype="multipart/form-data" id="form-upload" style="display: none;"><input osctype="btn_upload_image" type="file" name="file" /></form>');
	
	$('#form-upload input[name=\'file\']').trigger('click');	
	
	$('[osctype="btn_upload_image"]').fileupload({
				
    	dataType: 'json',
        url: "{:url('Aftersales/upload_image')}",	      
        add: function (e, data) {
            art.dialog({id:'loading',lock: true,title:'上传中'});	
            data.submit();
        },      
        done: function (e,data) {
        	
        	art.dialog.list['loading'].close();	
        	
        	var json=data.result;	
        	
			if(json.error){
				art.dialog({content:json.error, lock: true});
			}
			if(json.thumb){
				var img='<a target="_blank" href="/public/uploads/'+json.src+'"><img src="'+json.thumb+'"/></a>';
				img+='<input name="img['+count+']" type="hidden" value="'+json.src+'" />';
				$('#img_box').append(img);
				++count;
			}
 		}
   	});
	
});

$('#apply').click(function(){
	$.ajax({
			url: "{:url('Aftersales/apply')}",
			type: 'post',
			data: $('#refund_form input[type=\'text\'],#refund_form input[type=\'hidden\'],#refund_form textarea,#refund_form select'),
			dataType: 'json',
			beforeSend: function() {
				$('#apply').attr('disabled', true);
				art.dialog({id:'loading',lock: true,title:'加载中'});	
			},	
			complete: function() {
				$('#apply').attr('disabled', false); 
				art.dialog.list['loading'].close();			
			},
			success: function(json) {
				
				if (json['error']) {			
					art.dialog({
						content:json['error'],
						lock: true,
						ok: function () {}				    
					});																																		
				}else if(json['success']){
					
					if(json['url']){
						location = json['url'];
					}
								
					art.dialog({
						content:json['success'],
						lock: true,
						ok: function () {
							location = json['url'];
						}				    
					});				
				}  
			}
		});	
});

</script>
{/block}